package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.bean.ContestCollectBean;
import com.example.administrator.yuejian_2.viewholder.ContestCollectListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/10.
 */

public class ContestCollectListAdapter extends RecyclerView.Adapter {


    private List<ContestCollectBean> contest = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;
    private int cid,uid;

    public ContestCollectListAdapter(Context context, List<ContestCollectBean> contest){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.contest.addAll(contest);
        SharedPreferences sharedPreferences = context.getSharedPreferences("userInfo",
                Context.MODE_PRIVATE);
        uid = sharedPreferences.getInt("user_id",0);

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_contestcollect,parent,false);
        ContestCollectListViewHolder holder = new ContestCollectListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ContestCollectListViewHolder contestholder = (ContestCollectListViewHolder) holder;
        ContestCollectBean contestlist = contest.get(position);
        contestholder.contestname.setText(contestlist.getCon_title());
        String picture = contestlist.getCon_pic();
        if (!picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+picture)
                    .into(contestholder.contestpic);

        final int cid = contestlist.getCon_id();
//        contestholder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(context, ContestDetailActivity.class);
//                intent.putExtra("con_id",cid);
//                context.startActivity(intent);
//
//            }
//        });


    }

    @Override
    public int getItemCount() {

        return contest.size();
    }
}

